<template>
    <div v-show="!show">
    </div>
</template>

<script>
export default {
  name: 'GetToken',
  data () {
    return {
      show: true
    }
  },
  methods: {
    getToken () {
      // token
      var token = 'TIANPU'
      // 时间戳
      var timeStamp = Date.parse(new Date())
      timeStamp = timeStamp.toString()
      timeStamp = timeStamp.substr(0, timeStamp.length - 3)
      // 随机生成字符串
      var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
      var randomStr = 'z'
      for (var i = 0; i < 8; i++) {
        randomStr += chars.substr(parseInt(Math.random() * chars.length - 1), 1)
      }
      // 生成签名
      var arr = []
      arr.unshift(token, timeStamp, randomStr)
      arr.sort()
      arr = arr.toString().replace(/,/g, '')
      // arr = SHA1(arr)
      // arr = this.md5(arr)
      // console.log(arr)
      var signature = arr.toUpperCase()
      var tokenStr = {
        t: timeStamp,
        r: randomStr,
        z: signature
      }
      return tokenStr
    }
  },
  mounted () {
    this.getToken()
  }
}
</script>

<style lang="stylus" scoped>

</style>
